package com.ruoyi.web.controller.visit;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.visit.domain.LetterVisit;
import com.ruoyi.visit.service.ILetterVisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 信访投诉Controller
 * 
 * @author yxf
 * @date 2021-08-22
 */
@RestController
@RequestMapping("/visit/letter")
public class LetterVisitController extends BaseController
{
    @Autowired
    private ILetterVisitService letterVisitService;

    /**
     * 查询信访投诉列表
     */
    @PreAuthorize("@ss.hasPermi('visit:letter:list')")
    @GetMapping("/list")
    public TableDataInfo list(LetterVisit letterVisit)
    {
        startPage();
        List<LetterVisit> list = letterVisitService.selectLetterVisitList(letterVisit);
        return getDataTable(list);
    }

    /**
     * 导出信访投诉列表
     */
    @PreAuthorize("@ss.hasPermi('visit:letter:export')")
    @Log(title = "信访投诉", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LetterVisit letterVisit)
    {
        List<LetterVisit> list = letterVisitService.selectLetterVisitList(letterVisit);
        ExcelUtil<LetterVisit> util = new ExcelUtil<LetterVisit>(LetterVisit.class);
        return util.exportExcel(list, "信访投诉数据");
    }

    /**
     * 获取信访投诉详细信息
     */
    @PreAuthorize("@ss.hasPermi('visit:letter:query')")
    @GetMapping(value = "/{lvId}")
    public AjaxResult getInfo(@PathVariable("lvId") Long lvId)
    {
        return AjaxResult.success(letterVisitService.selectLetterVisitById(lvId));
    }

    /**
     * 新增信访投诉
     */
    @PreAuthorize("@ss.hasPermi('visit:letter:add')")
    @Log(title = "信访投诉", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LetterVisit letterVisit)
    {
        return toAjax(letterVisitService.insertLetterVisit(letterVisit));
    }

    /**
     * 修改信访投诉
     */
    @PreAuthorize("@ss.hasPermi('visit:letter:edit')")
    @Log(title = "信访投诉", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LetterVisit letterVisit)
    {
        return toAjax(letterVisitService.updateLetterVisit(letterVisit));
    }

    /**
     * 删除信访投诉
     */
    @PreAuthorize("@ss.hasPermi('visit:letter:remove')")
    @Log(title = "信访投诉", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lvIds}")
    public AjaxResult remove(@PathVariable Long[] lvIds)
    {
        return toAjax(letterVisitService.deleteLetterVisitByIds(lvIds));
    }
}
